﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.CMS.Message.DataAccess;

namespace TRPOP.CMS.Message
{
    public class MessageManage : IMessage
    {
        /// <summary>
        /// 添加、修改 留言类型
        /// </summary>
        /// <param name="oInfo"></param>
        /// <returns></returns>
        public bool SaveMessageType(model.MessageTypeInfo oInfo)
        {
            if (oInfo == null || String.IsNullOrEmpty(oInfo.nvcMessageTypeName))
            {
                return false;
            }
            return MessageTypeDAL.Save(oInfo);
        }

        /// <summary>
        ///  删除 留言类型
        /// </summary>
        /// <param name="intiMessageTypeID"></param>
        /// <returns></returns>
        public bool DeleteMessageType(int intiMessageTypeID)
        {
            return MessageTypeDAL.DeleteInfoById(intiMessageTypeID);
        }

        /// <summary>
        /// 获取信息列表（无分页）
        /// </summary>
        /// <param name="intTopn"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby">系统默认提供的排序规则: iDisplayOrder desc</param>
        /// <returns>符合条件的信息类型列表</returns>
        public List<model.MessageTypeInfo> GetMessageTypeInfoList(int intTopn, string strCondition, string strOrderby)
        {
            if(string.IsNullOrEmpty(strOrderby))
            {
                strOrderby = " iDisplayOrder DESC";
            }
            return MessageTypeDAL.GetListByCondition(intTopn, strCondition, strOrderby);
        }

        /// <summary>
        /// 添加、修改 留言状态
        /// </summary>
        /// <param name="oInfo"></param>
        /// <returns></returns>
        public bool SaveMessageStatus(model.MessageStatusInfo oInfo)
        {
            if (oInfo == null || !string.IsNullOrEmpty(oInfo.nvcMessageStatusName))
            {
                return false;
            }
            return MessageStatuDAL.Save(oInfo);
        }

        /// <summary>
        /// 删除 留言状态
        /// </summary>
        /// <param name="intiMessageStatusID"></param>
        /// <returns></returns>
        public bool DeleteMessageStatus(int intiMessageStatusID)
        {
            return MessageStatuDAL.DeleteInfoById(intiMessageStatusID);
        }

        /// <summary>
        /// 获取留言状态列表
        /// </summary>
        /// <param name="intTopn"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby">系统默认提供的排序规则: iDisplayOrder desc</param>
        /// <returns></returns>
        public List<model.MessageStatusInfo> GetMessageStatusList(int intTopn, string strCondition, string strOrderby)
        {
            if (string.IsNullOrEmpty(strOrderby))
            {
                strOrderby = " iDisplayOrder DESC ";
            }
            return MessageStatuDAL.GetListByCondition(intTopn, strCondition, strOrderby);
        }

        /// <summary>
        /// 新增、修改 留言信息
        /// </summary>
        /// <param name="oInfo"></param>
        /// <returns></returns>
        public bool SaveMessage(model.MessageInfo oInfo)
        {
            if (oInfo == null || string.IsNullOrEmpty(oInfo.nvcMessageTitle) || oInfo.iMessageStatusID <= 0 || oInfo.iMessageTypeID <= 0)
            {
                return false;
            }
            return MessageDAL.Save(oInfo);
        }

        /// <summary>
        ///根据留言ID 获取留言信息
        /// </summary>
        /// <param name="intiMessageID"></param>
        /// <returns></returns>
        public model.MessageInfo GetMessageInfo(int intiMessageID)
        {
            return MessageDAL.GetInfoById(intiMessageID);
        }

        /// <summary>
        /// 删除留言信息(软删除)
        /// </summary>
        /// <param name="intiMessageID"></param>
        /// <returns></returns>
        public bool DeleteMessageInfo(int intiMessageID)
        {
            model.MessageInfo oInfo = MessageDAL.GetInfoById(intiMessageID);

            if(oInfo==null)
            {
                return false;
            }
            else
            {
                oInfo.bIsDelete = true;//true为已被删除
            }
            return MessageDAL.Save(oInfo);
        }

        /// <summary>
        /// 获取留言信息的分页数据
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<model.MessageInfo> GetMessageInfoListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            return MessageDAL.GetListByPager(intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount);
        }

        /// <summary>
        /// 新增、编辑 留言回复信息
        /// </summary>
        /// <param name="oInfo"></param>
        /// <returns></returns>
        public bool SaveMessageReply(model.MessageReplyInfo oInfo)
        {
            if (oInfo == null || oInfo.iMessageID <= 0 ||string.IsNullOrEmpty( oInfo.ntMessageReplyContent) ||string.IsNullOrEmpty( oInfo.dtMessageReplyTime.ToString()))
            {
                return false;
            }
            return MessageReplyDAL.Save(oInfo);
        }

        /// <summary>
        /// 获取 留言回复信息
        /// </summary>
        /// <param name="intiMessageReplyID"></param>
        /// <returns></returns>
        public model.MessageReplyInfo GetMessageReply(int intiMessageReplyID)
        {
            return MessageReplyDAL.GetInfoById(intiMessageReplyID);
        }

        /// <summary>
        /// 删除留言回复信息
        /// </summary>
        /// <param name="intiMessageReplyID"></param>
        /// <returns></returns>
        public bool DeleteMessageReply(int intiMessageReplyID)
        {
            return MessageReplyDAL.DeleteInfoById(intiMessageReplyID);
        }

        /// <summary>
        /// 获取留言回复信息的分页数据
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<model.MessageReplyInfo> GetMessageReplyInfoListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            return MessageReplyDAL.GetListByPager(intPageNumber, intPageSize, strCondition, strOrderby, out intRecordCount);
        }

        /// <summary>
        /// 获取 留言+回复 信息的分页数据
        /// </summary>
        /// <param name="intPageNumber"></param>
        /// <param name="intPageSize"></param>
        /// <param name="strCondition"></param>
        /// <param name="strOrderby"></param>
        /// <param name="intRecordCount"></param>
        /// <returns></returns>
        public List<model.Message_MessageReplyInfo> GetMessage_MessageReplyInfoListByPager(int intPageNumber, int intPageSize, string strCondition, string strOrderby, out int intRecordCount)
        {
            return MessageDAL.GetMessage_MessageReplyInfoListByPager(intPageNumber, intPageSize, strCondition, strOrderby, out  intRecordCount);
        }
    }
}
